package com.liqing.lqrpc.server;

import io.vertx.core.Vertx;

/**
 * TODO Vertx服务器
 *
 * @author Li Qing
 * @date 2024/7/4 0:08
 */
public class VertxHttpServer implements HttpServer {
    @Override
    public void doStart(int port) {
        //创建Vertx 实例
        Vertx vertx = Vertx.vertx();
        //创建 http 服务器
        io.vertx.core.http.HttpServer server = vertx.createHttpServer();
        //监听端口并处理请求
        server.requestHandler(new HttpServerHandler());
        // 启动http 服务器并监听指定端口
        server.listen(port, result -> {
            if (result.succeeded()) {
                System.out.println("Server started on port " + port);
            } else {
                System.out.println("Server failed to start on port " + port);
            }
        });
    }
}
